﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DMS.DAL;
using DMS.Logic;
namespace WebUI.library
{
    public partial class add : System.Web.UI.Page
    {
        int id = 0;
        DocumentLibrary dl = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                id = int.Parse(Request.QueryString["id"]);
                dl = BL.getInstance().getDocumentLibraryById(id);
            }
            if (!IsPostBack)
            {
                string spId = "";
                if (dl != null)
                {
                    spId = dl.StorageProvider.ID.ToString();
                    chkApproval.Checked = dl.IsApprovalRequired;
                    chkReadOnly.Checked = dl.IsReadOnly;
                    chkVersioning.Checked = dl.IsVersioningEnabled;
                    txtName.Text = dl.Name;
                    txtURL.Text = dl.URL;
                }
                loadDrp(spId);
            }
        }

        void loadDrp(string selected)
        {
            drpStorage.DataSource = BL.getInstance().getAllStorageProvider();
            drpStorage.DataValueField = "ID";
            drpStorage.DataTextField = "Description";
            if (!string.IsNullOrEmpty(selected))
                drpStorage.SelectedValue = selected;
            drpStorage.DataBind();
            drpStorage.Items.Insert(0, new ListItem());
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (dl == null){
                dl = new DocumentLibrary();
                dl.CreationDate = DateTime.Now;
            }
            //dl.CreationDate = DateTime.Now;
            dl.IsApprovalRequired = chkApproval.Checked;
            dl.IsReadOnly = chkReadOnly.Checked;
            dl.IsVersioningEnabled = chkReadOnly.Checked;
            dl.Name = txtName.Text;
            dl.URL = txtURL.Text;
            BL.getInstance().saveDocumentLibrary(dl, 1,1);
        }

    }
}
